package Proyecto;

import java.beans.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author caty
 */
public class Conectar {
public static Connection conexion;
    public  Statement statement;
   
    ResultSet resultset;
    

    static String bd = "muebles";//nombre de mi base de datos
    static String login = "";
    static String password = "";
    static String url = "jdbc:mysql://localhost/"+bd;
public void abrirConexion() {
    login=Inicio.JTextField1.getText().toString();
     password=Inicio.JPasswordField1.getText().toString();

try {
         Class.forName("com.mysql.jdbc.Driver").newInstance();
         //METODO ESTATICO FORNAME


conexion = DriverManager.getConnection(url,login,password);
if(conexion!=null){
    System.out.println("ddddd");
}
            // SE CREA LA CONEXION

} // fin del try
	     catch ( Exception sqlException ) {
	     JOptionPane.showMessageDialog( null, "error");
}
}
public void cerrarConexion() {
		try {

           conexion.close();//se cierra la conexiom
           JOptionPane.showMessageDialog(null,"se ha cerrado la conexion");
        }

        catch ( SQLException sqlException ) {
           JOptionPane.showMessageDialog(null, "error");
           System.exit( 1 );
        }
	}
}
